import {
  defineStore
} from 'pinia'

export const cartStore = defineStore('shoppingCart', {


  state: () => ({
    list: [],
  }),
  actions: {
    set(goodIds) {
      this.list = goodIds
    },
    add(goodId) {
      const idx = this.list.findIndex((e) => e === goodId)
      if (idx === -1) {
        this.list.push(goodId)
      }
    },
    delete(goodsId) {
      const idx = this.list.findIndex((e) => e === goodsId)
      if (idx !== -1) {
        this.list.splice(idx, 1)
      }
    },
    delAll() {
      this.list = []
    }
  }
})
